var recIdArray = [];
var recstatusArray = [];

$(function(){
	selectGroups();
	getWorkerType();
});

var tableData = {
	url : ctp + "/payrollController/payrollSearch.shtml",
	hidden : [ "recstatus=REC_STATUS" ],
	propertys : [ "NAME","JOBNO","WORKTYPE","GROUPNAME","WORK_HOURS","WORK_QUANTITY","CHARGETYPE","UNITPAY","SALARY","WORK_REWARD","WORK_SUBSIDY","ATT_DEDUCTION","OTHER_DEDUCTION","WXYJ" ,"GS","SHOULD_GIVE","REAL_GIVE","NO_GIVE","REC_STATUS"],
	globalCheck : [["recId", recIdArray],["recstatus", recstatusArray]],
	startLoad : function() {
		getListData(this);
	}
};
function searchData(curr) {
	setTagAndValue("form1", "curr", curr);
	tableData.startLoad();
}
$(document).ready(function() {
	$("#beginTime").val(setBeginTime());
	searchData();
});




function exportConfirm(recId){
	var formSerialize =$("#form1").serialize();
	jconfirm("exportData('"+formSerialize+"')","确认要导出工资数据吗？");	
}
function exportData(formSerialize){
	location.href=ctp+"/payrollController/exportPayroll.shtml?"+formSerialize;
}

//发放工资提交审核
function payroll(){
	var recstatus = getCheckIds(null, "recstatus");
	if(recstatus.indexOf("待审批") >= 0){
		jalert("你选择的工人中，存在已提交过申请的，请确认！");
		return;
	}
	if(recstatus.indexOf("部分发放") >= 0 || recstatus.indexOf("全部发放") >= 0){
		jalert("你选择的工人中，存在已发放工资的，请确认！");
		return;
	}
	
	var beginTime = $("#beginTime").val();
	if(beginTime == ''){
		jalert("请选择结算日期！");
		return;
	}
	var recIds = getCheckIds();
	if(recIds == '' || recIds == null){
		jalert("请选择发放工资对象！");
		return;
	}
	if(recIds.length > 1024){
		jalert("你选择的员工数量过多，请分批次处理，建议一次处理25个最佳！");
		return;
	}

	
	layui.layer.open({
        type: 2,
        area: ['1100px', '500px'],
        title: "工资发放申请",
        fixed: false,
        maxmin: false,
        content: ctp + "/payrollController/pageEditSalary.shtml?workerId=" + recIds + "&beginTime=" + beginTime
    });
//	location.href = ctp + "/payrollController/pageEditSalary.shtml?workerId=" + recIds + "&beginTime=" + beginTime;
}


function selectGroups(){
    $.ajax({
        url: ctp + "/groupController/selectGroups.shtml", 
        data: {},
        type: "POST", 
        cache : false, 
        dataType: "json",
        success: function(data) {
            var list = data.list; 
			var $str='';
			$str +='<select class="smart-body_select" name="groupid" id="groupid">';
			$str +='<option value="">全部</option>';
        	for (var i = 0; i < list.length; i++) {
        		var l = list[i];
        		$str+='<option value="'+l.REC_ID+'">'+l.NAME+'</option>';
        	}
        	$str+='</select>';
        	$('#group').append($str);
        }
    });
}


function getWorkerType() {
	$.ajax({
		url : ctp + "/sysdictController/getDictListByType.shtml",
		data : {
			dicType : 'WORKER_TP'
		},
		type : "POST",
		cache : false,
		dataType : "json",
		success : function(data) {
			var list = data.list;
			var $str = '';
			$str += '<option value="">全部</option>';
			for (var i = 0; i < list.length; i++) {
				var l = list[i];
				$str += '<option value="' + l.rec_value + '">' + l.rec_value
						+ '</option>';
			}
			$('#workeType').html($str);
		}
	});
}


function setBeginTime(){
	var d = new Date();
	var year = d.getFullYear() + "";
	var month = d.getMonth();
	if(month < 10) month = "0" + month;
	return year + "-" + month;
}

function promptInfo(){
	recIdArray.splice(0,recIdArray.length);
	recstatusArray.splice(0,recstatusArray.length);
	jalert9("发放工资申请提交成功！");
}